package com.webchat.rmi.ugc;


import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.domain.vo.request.ChattingRequestVO;
import com.webchat.domain.vo.response.chatting.ChattingListResponseVO;
import com.webchat.domain.vo.response.mess.ChatMessageResponseVO;
import com.webchat.rmi.interceptor.RpcRequestInterceptor;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * 声明用户对话消息基础服务 客户端
 */
@FeignClient(name = "webchat-ugc-service",
        contextId = "ugcChatMessageClient",
        configuration = RpcRequestInterceptor.class)
public interface ChatMessageClient {


    /**
     * 聊天场景 - 查询用户最近对话列表
     *
     * @param userId        当前登录用户uid
     * @param lastChatTime  开始查询时间
     * @param size          最大获取对话列表条数, 默认取100条
     * @return
     */
    @GetMapping("/ugc-service/chat/message/chatting/list/{userId}")
    APIResponseBean<List<ChattingListResponseVO>> listChatting(
            @PathVariable String userId,
            @RequestParam(name = "lastChatTime", required = false) Long lastChatTime,
            @RequestParam(name = "size", required = false, defaultValue = "100") Integer size);


    /**
     * 加入对话到用户对话消息列表
     * 注：当前API不支持消息持久化，请注意在消息内容持久化之后调用（如果需要），这里完全依赖 redis 缓存
     *
     * @param chattingRequest
     * @return
     */
    @PostMapping("/ugc-service/chat/message/chatting/list/add")
    APIResponseBean<Boolean> addChattingList(@RequestBody ChattingRequestVO chattingRequest);

    /**
     * 查询与用户的对话列表
     *
     * @param sourceAccount
     * @param targetAccount
     * @param size
     * @param lastId
     * @param fixedMessageId
     * @return
     */
    @GetMapping("/ugc-service/chat/message/list")
    APIResponseBean<List<ChatMessageResponseVO>> list(@RequestParam(value = "sourceAccount", required = false) String sourceAccount,
                                                      @RequestParam(value = "targetAccount", required = false) String targetAccount,
                                                      @RequestParam(value = "size", required = false, defaultValue = "50") Integer size,
                                                      @RequestParam(value = "lastId", required = false) Long lastId,
                                                      @RequestParam(value = "fixedMessageId", required = false) Long fixedMessageId);


    /**
     * 用户IM聊天数据查询
     *
     * @param sourceUserId
     * @param targetUserId
     * @param startTime
     * @param endTime
     * @param count
     * @return
     */
    @GetMapping("/ugc-service/chat/message/query")
    APIResponseBean<List<String>> query(@RequestParam String sourceUserId,
                                        @RequestParam String targetUserId,
                                        @RequestParam(required = false) Long startTime,
                                        @RequestParam(required = false) Long endTime,
                                        @RequestParam(required = false, defaultValue = "1000") Integer count);
}
